<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>快递管理系统</title>
    <meta name="Copyright" content="Douco Design."/>
    <link href="css/public.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/global.js"></script>
</head>
<body>
<div id="dcWrap">

    <div id="dcMain">
        <!-- 当前位置 -->
        <div id="manager" class="mainBox" style="height:auto!important;height:550px;min-height:550px;">
            <h3>用户登陆</h3>
            <form action="/delivery_system/user/login" method="post" onsubmit="return checkForm()">
                <table width="100%" border="0" cellpadding="8" cellspacing="0" class="tableBasic">
                    <tr>
                        <td width="100" align="right">用户名</td>
                        <td>
                            <input id="usernameInput" type="text" name="username" onchange="checkUsername()" size="40" class="inpMain" />
                            &nbsp; &nbsp;
                            <span id="usernameMsg"></span>
                        </td>
                    </tr>
                    <tr>
                        <td width="100" align="right">密码</td>
                        <td>
                            <input id="passwordInput" type="password" name="password" onchange="checkPassword()" size="40" class="inpMain"/>
                            &nbsp; &nbsp;
                            <span id="passwordMsg"></span>
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td>
                            <input type="submit" name="submit" class="btn" value="登录"/>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
    <div class="clear"></div>
    <div id="dcFooter">
        <div id="footer">
            <div class="line"></div>
            <ul>
                版权所有 © 2024-2025 尚硅谷教育，并保留所有权利。
            </ul>
        </div>
    </div><!-- dcFooter 结束 -->
    <div class="clear"></div>
</div>
</body>
<script>
    //1.定义用户名和密码的正则表达式
    var usernameReg = /^[a-zA-Z][a-zA-Z0-9]{5,9}$/;
    var passwordReg = /^[a-zA-Z0-9]{6,12}$/;

    //2.定义两个变量用来标记用户名和密码填写内容是否正确
    var usernameFlag;
    var passwordFlag;

    //3.校验用户名
    function checkUsername(){
        //获取用户名输入框中的value
        var usernameElement = document.getElementById("usernameInput");
        var usernameValue = usernameElement.value;
        //获取span标签对象,用于将来在span中显示用户名格式是否正确的提示信息
        var spanElement = document.getElementById("usernameMsg");
        //校验输入的用户名是否符合正则表达式
        if (usernameReg.test(usernameValue)){
            spanElement.innerHTML = "<font style='color:green'>用户名格式正确</font>";
            usernameFlag = true;
        }else{
            spanElement.innerHTML = "<font style='color:red'>用户名格式不正确</font>";
            usernameFlag = false;
        }
    }

    //4.校验密码
    function checkPassword(){
        //获取密码输入框中的value
        var passwordvalue = document.getElementById("passwordInput").value;
        //获取span标签,用于将来在span中显示密码格式是否正确的提示信息
        var spanElement = document.getElementById("passwordMsg");
        //判断输入的密码是否符合正则表达式
        if (passwordReg.test(passwordvalue)){
            spanElement.innerHTML = "<font style='color:green'>密码格式正确</font>";
            passwordFlag = true;
        }else{
            spanElement.innerHTML = "<font style='color:red'>密码格式不正确</font>";
            passwordFlag = false;
        }
    }

    //5.判断表单是否能提交
    function checkForm(){
        return usernameFlag && passwordFlag;
    }
</script>
</html>